package user_assets

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInsertBankInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 添加
func NewUserInsertBankInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInsertBankInfoLogic {
	return &UserInsertBankInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserInsertBankInfoLogic) UserInsertBankInfo(req *types.UserInsertBankInfoRequest) (resp *types.UserInsertBankInfoResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.UserChannel.UserBankInsert(l.ctx, &rpc.UserBankInfoInsertRequest{
		UserId:     req.UserId,
		Username:   req.UserName,
		CardNumber: req.CardNum,
		IfscCode:   req.IFSCCode,
		Email:      req.Email,
		Phone:      req.Phone,
		BankId:     req.BankId,
		Province:   req.Province,
		City:       req.City,
		BranchBank: req.BranchBank,
		AgentId:    req.AgentId,
	})

	if err != nil {
		return &types.UserInsertBankInfoResponse{
			IsInsert: false,
		}, err
	}
	return &types.UserInsertBankInfoResponse{
		IsInsert: true,
	}, err
}
